package com.sskj.mine.ui.activity;


import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.sskj.common.adapter.MyFragmentPagerAdapter;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.presenter.LoginActivityPresenter;
import com.sskj.mine.ui.fragment.LoginFragment;
import com.sskj.mine.ui.fragment.RegisterFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import yanzhikai.textpath.AsyncTextPathView;
import yanzhikai.textpath.SyncTextPathView;

@Route(path = RConfig.MINE_LOGIN)//登录主界面（包含登录Fragment   注册Fragment）
public class LoginActivity extends BaseActivity<LoginActivityPresenter> {

    @BindView(R2.id.login_tablayout)
    SlidingTabLayout loginTablayout;
    @BindView(R2.id.login_register_all)
    ViewPager loginRegisterAll;
    @BindView(R2.id.sign_type)
    AsyncTextPathView signType;
    private List<String> listTitle;
    private List<Fragment> listFragment;

    @Override
    protected int getLayoutResId() {
        return R.layout.mine_activity_login;
    }

    @Override
    public LoginActivityPresenter getPresenter() {
        return new LoginActivityPresenter();
    }

    /**
     * 注册成功页面跳转方法
     */
    public void skipFragment() {
        loginRegisterAll.setCurrentItem(0);
    }

    @Override
    protected void initView() {
        listTitle = new ArrayList<>();
        listTitle.add("登录");
        listTitle.add("注册");
        listFragment = new ArrayList<>();
        listFragment.add(LoginFragment.newInstance());
        listFragment.add(RegisterFragment.newInstance());
        loginRegisterAll.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(), listTitle, listFragment));
        loginTablayout.setViewPager(loginRegisterAll);
        loginRegisterAll.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        signType.setText("Sign in");
                        signType.startAnimation(0, 1);
                        break;
                    case 1:
                        signType.setText("Sign up");
                        signType.startAnimation(0, 1);
                        break;
                }
            }
        });
        loginTablayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                switch (position) {
                    case 0:
                        signType.setText("Sign in");
                        break;
                    case 1:
                        signType.setText("Sign up");
                        break;
                }
            }

            @Override
            public void onTabReselect(int position) {
            }
        });
    }

    @Override
    protected void initData() {
        super.initData();
    }


}
